﻿<!DOCTYPE>
<html>
<head>
    <meta http-equiv="X-UA-Compatible" content="IE=EDGE;IE=11;IE=8,chrome=1" />
    <title>热表订单批次开卡主页面</title>
    <link href="/InSiteWebApplication/Content/Easyui/themes/metro/easyui.css" rel="stylesheet" />
    <link href="/InSiteWebApplication/Content/Easyui/custom-easyui.css" rel="stylesheet" />
    <link href="/InSiteWebApplication/Content/Easyui/themes/icon.css" rel="stylesheet" />
</head>
<body>
    <div id="mainSec">
        <div class="panelSection">
            <div class="easyui-panel " title="查询区域" style="padding: 3px; width: 100%" data-options="closable:false,collapsible:true,minimizable:false,maximizable:false">
                <form id="queryForm" action="">
                <div style="margin: 3px 0px 3px 3px">
                    <div style="float: left;">
                        <div class="divLabel" style="margin-bottom: 5px; color: Red">
                            订单号：</div>
                        <input id="txtMfgOrderName" name="mfgOrderName" class="easyui-textbox" style="width: 150px;
                            height: 20px" />
                    </div>
                    <div style="float: left; margin-left: 10px">
                        <div class="divLabel" style="margin-bottom: 5px">
                            件号：</div>
                        <input id="txtProductName" name="productName" class="easyui-textbox" style="width: 150px;
                            height: 20px" />
                    </div>
                    <div style="float: left; margin-left: 10px">
                        <div class="divLabel" style="margin-bottom: 5px">
                            状态：</div>
                        <select id="txtStatus" name="status" class="easyui-combobox" style="width: 150px;
                            height: 20px">
                            <option value="0">全部</option>
                            <option value="1">未开卡</option>
                            <option value="2">已开卡</option>
                        </select>
                    </div>
                    <div style="float: left; margin-left: 10px">
                        <div class="divLabel" style="margin-bottom: 5px">
                            MRP控制者：</div>
                        <input id="txtMrpControler" name="mrpControler" class="easyui-textbox" style="width: 120px;
                            height: 20px" />
                    </div>
                    <div style="float: left; margin-left: 20px">
                        <button id="btnSearch" class="easyui-linkbutton" type="button" style="margin-top: 16px;
                            width: 100px">
                            查询</button>
                        <button id="btnReset" class="easyui-linkbutton" type="button" style="margin-top: 16px;
                            margin-left: 5px; width: 60px">
                            重置</button>
                    </div>
                    <div style="clear: both">
                    </div>
                </div>
                </form>
            </div>
        </div>
        <div class="panelSection">
            <div class="easyui-panel " title="结果区域" style="padding: 3px; width: 100%" data-options="closable:false,collapsible:true,minimizable:false,maximizable:false">
                <div style="margin: 3px 0px 3px 3px; float: left; width: 60%">
                    <table id="gdOrderInfo" class="easyui-datagrid" style="width: 100%; height: 350px"
                        data-options="rownumbers:true,singleSelect:true,selectOnCheck:true">
                    </table>
                    <div id="pp" style="float: right" class="easyui-pagination" data-options="   
                 layout:['first','prev','next','last','manual','info'],              
                    total: 0,
                    showPageList: false,
                    showPageInfo: false,
                    showRefresh: false,
                    afterPageText:'共&nbsp{pages}&nbsp页',
                    buttons:[{
                            iconCls:'',
                            text:'Go',
                            id:'pageGo'
                    }]  
                ">
                    </div>
                </div>
                <div style="margin: 3px 0px 3px 3px; float: left; width: 30%">
                    <table id="gdContainerInfo" class="easyui-datagrid" style="width: 100%; height: 350px"
                        data-options="rownumbers:true">
                    </table>
                </div>
            </div>
        </div>
        <div class="panelSection">
            <div class="easyui-panel " title="按钮区域" style="padding: 3px; width: 100%" data-options="closable:false,collapsible:true,minimizable:false,maximizable:false">
                <div style="margin: 3px 0px 3px 3px">
                    <button id="btnStart" class="easyui-linkbutton" type="button" style="width: 120px;
                        height: 24px;">
                        开卡</button>
                </div>
            </div>
        </div>
    </div>
    <div id="dg">
    </div>
</body>
</html>
<script src="/InSiteWebApplication/Scripts/CustomPageJs/ReferenceJsLib.js" type="text/javascript"></script>
<script src="/InSiteWebApplication/Content/Easyui/jquery.min.js" type="text/javascript"></script>
<script src="/InSiteWebApplication/Content/Easyui/jquery.easyui.min.js" type="text/javascript"></script>
<script src="/InSiteWebApplication/Content/Easyui/easyui-lang-zh_CN.js" type="text/javascript"></script>
<script src="/InSiteWebApplication/Scripts/CustomPageJs/CustomCommon.js" type="text/javascript"></script>
<script type="text/javascript">
    /*
    创建人：zhangrj
    日期：2024-05-23
    描述：热表订单开卡主页面
    */
    var page = {
        pageTotal: 0,
        pageSize: 20,
        pageNumber: 1,
        rootPath: getRootPath(), //网站根路径
        ajaxUrl: getRootPath() + "/Ashx/ReBiaoConainer/RbOrderContainerStartHandler.ashx",
        //初始化页面
        init: function () {
            page.bind();
            customizedEasyuiPagination('pp'); //定制化分页
        },
        //页面事件绑定
        bind: function () {
            //列表加载
            $("#gdOrderInfo").datagrid({
                onLoadSuccess: function (data) {
                    $('#pp').pagination('refresh', {	// 改变选项，并刷新分页栏信息
                        total: page.pageTotal,
                        pageSize: page.pageSize,
                        pageNumber: page.pageNumber
                    });
                    customizedEasyuiPagination('pp'); //定制化分页
                },
                onClickRow: function (rowIndex, rowData) {
                    page.bindContainerInfo(rowData.MFGORDERID); //绑定批次信息
                },
                columns: [[
                 { field: 'ck', title: '选择', checkbox: true },
                 { field: 'MFGORDERNAME', title: '订单', width: 120 },
                 { field: 'MRPCONTROL', title: '控制者', width: 100 },
                 { field: 'ORDERQTY', title: '订单数', width: 60 },
                 { field: 'WIPQTY', title: '在制数', width: 60 },
                 { field: 'PRODUCTNAME', title: '零件号', width: 150 },
                 { field: 'PRODUCTDESC', title: '零件名称', width: 120 },
                 { field: 'PLANNEDSTARTDATE', title: '计划开始日期', width: 100,
                     formatter: function (value, row, index) {
                         if (!isNullOrWhiteSpaceStr(value)) {
                             return dayjs(value).format('YYYY-MM-DD');
                         }
                     }
                 },
                 { field: 'PLANNEDCOMPLETIONDATE', title: '计划完成日期', width: 100,
                     formatter: function (value, row, index) {
                         if (!isNullOrWhiteSpaceStr(value)) {
                             return dayjs(value).format('YYYY-MM-DD');
                         }
                     }
                 }
                ]]
            });
            $("#gdContainerInfo").datagrid({
                columns: [[
                 { field: 'CONTAINERNAME', title: '批次号', width: 200 },
                 { field: 'QTY', title: '在制数', width: 80 },
                 { field: 'ORIGINALSTARTDATE', title: '开卡日期', width: 100,
                     formatter: function (value, row, index) {
                         if (!isNullOrWhiteSpaceStr(value)) {
                             return dayjs(value).format('YYYY-MM-DD');
                         }
                     }
                 }
                ]]
            });
            //查询按钮
            $('#btnSearch').on("click", function () {
                page.clearPage(false, true, true);
                page.pageNumber = 1;
                page.search();
            });
            //分页事件
            $('#pp').pagination({
                onSelectPage: function (pageNumber, pageSize) {
                    customizedEasyuiPagination('pp'); //定制化分页
                    page.pageSize = pageSize; page.pageNumber = pageNumber;
                    page.search();
                }
            });
            //绑定分页go按钮
            $('#pageGo').on("click", function () {
                var pageNumber = $(this).parents('tr').find('.pagination-num').val();
                page.pageNumber = pageNumber;
                page.search();
            });
            //清除按钮
            $('#btnReset').on("click", function () {
                page.clearPage(true, true, true);
            });
            //状态更改
            $('#txtStatus').combobox({
                onSelect: function () {
                    page.clearPage(false, true, true);
                }
            });
            //扫描批次事件
            $('#txtMfgOrderName').textbox({
                onChange: function (n, o) {
                    page.pageNumber = 1;
                    page.search();
                }
            });
            //开卡
            $('#btnStart').on("click", function () {
                page.clearPage(false, false, true);
                page.disableBtn();
                page.openStartForm();
            });
        },
        //查询
        search: function () {
            page.disableBtn();
            var params = {
                pageSize: page.pageSize,
                pageIndex: page.pageNumber
            };
            var datas = $("#queryForm").serializeArray();
            $.each(datas, function () {
                params[this.name] = this.value;
            });
            var formData = {
                action: "GetMfgOrderList",
                params: JSON.stringify(params)
            };
            page.post(page.ajaxUrl, formData, true, function (res) {
                page.enableBtn();
                if (!res.Result) {
                    displayMessage(res.Message, res.Result);
                    return;
                }
                page.pageTotal = res.RowCount;
                $("#gdOrderInfo").datagrid('loadData', { total: res.RowCount, rows: res.DBTable });
            });
        },
        //绑定批次信息
        bindContainerInfo: function (mfgOrderId) {
            clearEasyuiDataGrid("gdContainerInfo"); //清空列表
            var formData = {
                action: "GetContainerInfoByMfgOrder",
                mfgOrderId: mfgOrderId
            };
            page.post(page.ajaxUrl, formData, true, function (res) {
                if (!res.Result) {
                    displayMessage(res.Message, res.Result);
                    return;
                }
                $("#gdContainerInfo").datagrid('loadData', { rows: res.DBTable });
            });
        },
        //打开开卡弹窗
        openStartForm: function () {
            var selected = $("#gdOrderInfo").datagrid("getChecked");
            if (selected.length === 0) {
                page.enableBtn();
                displayMessage("请选择数据", false);
                return;
            }
            page.post(page.ajaxUrl, { action: "IsValidOrderContainer", mfgOrderName: selected[0].MFGORDERNAME }, true, function (res) {
                if (!res.Result) {
                    page.enableBtn();
                    displayMessage(res.Message, res.Result);
                    return;
                }
                var paras = $.param({ v: new Date().getTime(), orderName: selected[0].MFGORDERNAME, productID: selected[0].PRODUCTID }); //拼接url参数
                var url = "/InSiteWebApplication/forms/Custom/ReBiao/RbOrderContainerStartPage.html?" + paras;
                $('#dg').dialog({
                    title: '热表订单流水卡创建',
                    width: 1050,
                    height: 500,
                    content: "<iframe scrolling='auto' frameborder='0' src='" + url + "' style='width:100%; height:100%; display:block;'></iframe>",
                    onClose: function () {
                        page.enableBtn();
                        page.clearPage(false, true, true);
                        page.search();
                    }
                });
            });

        },
        //禁用页面按钮
        disableBtn: function () {
            $("#mainSec").find(".easyui-linkbutton").each(function () {
                $(this).linkbutton('disable');
            });
        },
        //启用页面按钮
        enableBtn: function () {
            $("#mainSec").find(".easyui-linkbutton").each(function () {
                $(this).linkbutton('enable');
            });
        },
        //清除页面（查询区域，列表区域，是否清空消息）
        clearPage: function (query, list, msg) {
            if (query) {
                $("#txtMfgOrderName").textbox("setValue", "");
                $("#txtProductName").textbox("setValue", "");
                $("#txtStatus").combobox("setValue", "0");
                $("#txtMrpControler").textbox("setValue", "");
                page.pageNumber = 1; page.pagetotal = 0
                $('#pp').pagination('refresh', {
                    total: page.pageTotal,
                    pageSize: page.pageSize,
                    pageNumber: page.pageNumber
                });
            }
            if (list) {
                page.pageNumber = 1; page.pagetotal = 0
                clearEasyuiDataGrid("gdOrderInfo"); //清空列表
                clearEasyuiDataGrid("gdContainerInfo"); //清空列表
            }
            if (msg) {
                clearMessage();
            }
        },
        //post数据（路径，参数，是否异步，成功返回方法）
        post: function (url, param, async, callback) {
            $.ajax({
                type: "Post",
                url: url,
                data: param,
                cashe: false,
                async: async,
                dataType: "json",
                beforeSend: function () {
                    $.messager.progress({ text: '', msg: '处理中...' });
                },
                success: function (data) {
                    $.messager.progress('close');
                    callback(data);
                },
                error: function (XMLHttpRequest, textStatus, errorThrown) {
                    $.messager.progress('close');
                    displayMessage(XMLHttpRequest.responseText, false);
                    page.enableBtn();
                }
            });
        }
    }
    $(function () {
        page.init();
    });
</script>
